from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.time_sensor.time_after_07_30 import time_after_07_30
from jms.dwd.tab.dwd_dependent_hi.dwd_tab_barscan_send_base_hi_05 import jms_dwd__dwd_tab_barscan_send_base_hi_05
from jms.dwd.tab.dwd_dependent_hi.dwd_yl_oms_oms_waybill_incre_hi_05 import jms_dwd__dwd_yl_oms_oms_waybill_incre_hi_05
from jms.dwd.tab.dwd_dependent_hi.dwd_tab_barscan_bagging_base_hi_05 import jms_dwd__dwd_tab_barscan_bagging_base_hi_05
from jms.dwd.tab.dwd_dependent_hi.dwd_third_package_list_base_hi_05 import jms_dwd__dwd_third_package_list_base_hi_05
from jms.dim.dim_tmsnew_vehicle_line import jms_dim__dim_tmsnew_vehicle_line


jms_dm__dm_tab_in_center_package_waybill_base_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_tab_in_center_package_waybill_base_detail_dt',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    execution_timeout=timedelta(minutes=60),
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_tab_in_center_package_waybill_base_detail_dt_{{ execution_date | cst_ds }}',
    sql='jms/dm/dm_tab_in_center_package_waybill_base_detail_dt/execute.hql',
    driver_memory='4G',
    driver_cores=4,
    executor_cores=6,
    executor_memory='8G',
    num_executors=50,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 300,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 1600,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 900,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.sql.autoBroadcastJoinThreshold': 104857600,
          'spark.yarn.executor.memoryOverhead': 2048,
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=6'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 400,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 200,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
)

jms_dm__dm_tab_in_center_package_waybill_base_detail_dt << [
    jms_dwd__dwd_tab_barscan_bagging_base_hi_05,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_hi_05,
    jms_dwd__dwd_third_package_list_base_hi_05,
    jms_dwd__dwd_tab_barscan_send_base_hi_05,
    jms_dim__dim_tmsnew_vehicle_line,
    time_after_07_30
]
